//
//  TabBarController.m
//  Mango
//
//  Created by lanou3g on 16/5/4.
//  Copyright © 2016年 lanou3g. All rights reserved.
//

#import "TabBarController.h"
#import "HomeController.h"
#import "DiscoverController.h"
#import "MeTableViewController.h"
#import "NavigationController.h"
@interface TabBarController ()

@end

@implementation TabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
   //添加子控制器
    [self setupChildVc:[[HomeController alloc] init] title:@"首页" image:@"主页-1" selectedImage:@"主页"];
    
    [self setupChildVc:[[DiscoverController alloc] init] title:@"发现" image:@"发现-1" selectedImage:@"发现"];
    
    [self setupChildVc:[[MeTableViewController alloc] init] title:@"我" image:@"我-1" selectedImage:@"我"];
    
    //换肤
    [self updateSkinModel];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateSkinModel) name:SkinModelDidChangedNotification object:nil];
}

#pragma mark 更新皮肤模式 接到模式切换的通知后会调用此方法
-(void)updateSkinModel {
    NSString *currentSkinModel = [[NSUserDefaults standardUserDefaults] stringForKey:CurrentSkinModelKey];
    if ([currentSkinModel isEqualToString:NightSkinModelValue]) {
        self.tabBar.barTintColor = [UIColor colorWithRed:34/255.0 green:30/255.0 blue:33/255.0 alpha:1.0];
    } else {//日间模式
        self.tabBar.barTintColor = [UIColor whiteColor];
        self.tabBar.tintColor = [UIColor colorWithRed:252/255.0 green:65/255.0 blue:19/255.0 alpha:1.0];
    }
}
-(void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}


/**
 * 初始化子控制器
 */
- (void)setupChildVc:(UIViewController *)vc title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage
{
    // 设置文字和图片
    vc.navigationItem.title = title;
    vc.tabBarItem.title = title;
    vc.tabBarItem.image = [UIImage imageNamed:image];
    vc.tabBarItem.selectedImage = [UIImage imageNamed:selectedImage];
    
    // 包装一个导航控制器, 添加导航控制器为tabbarcontroller的子控制器
    NavigationController *nav = [[NavigationController alloc] initWithRootViewController:vc];
    [self addChildViewController:nav];
}



@end
